package com.MyApp.CompanyRank;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class UniversityData {
	public static int depth = 4;
	public static String dataDir = "rankingdata"; 
	public static String globalFileName = dataDir + File.separator+"GlobalList.txt";
//	/**
//	 * ider's file path
//	 */
//	public static String globalFileName ="F:"+ File.separator +"rankings" + File.separator + dataDir + File.separator+"GlobalList.txt";
    public static String cnFileName = dataDir + File.separator+"GlobalListcn.txt" ;
    
	public static String[] subjects = {"Philosophy", "Logic", "Mathematics", "Physics", 
		"Chemistry", "Biology", "Computer science", "Psychology", "Linguistics", 
		"Sociology", "History", "Architecture", "Economics", "Political science", 
		"Engineering", "Mechanical engineering", "Chemical engineering", "Civil engineering", "Electrical engineering", 
		"Library science","Journalism","Literature"};
	
	public static String[] cnSubjects = {"哲学", "逻辑", "数学", "物理", 
		"化学", "生物", "计算机科学", "心理学", "语言学", 
		"社会学", "历史", "建筑", "经济学", "政治学", 
		"工程", "机械工程", "化学工程", "土木工程", "电气工程", 
		"图书馆学", "新闻学","文学"};
	
	public static HashMap <String, String> subjectMap = getSubjectMap(subjects, cnSubjects);
	static HashMap<String, String> getSubjectMap(String[] subjects, String[] cnSubjects) {
		HashMap<String, String> ret = new HashMap<String, String> ();
		for (int i = 0; i< subjects.length; i++) {
			ret.put(subjects[i], cnSubjects[i]);
		}
		return ret;
	}
	
	static HashMap<String, String> buildEn2ZhMap(String enfile, String zhfile) throws FileNotFoundException, IOException {

		List<String> enl = readRegionList(enfile, "UTF-8");
		List<String> zhl = readRegionList(zhfile, "UTF-16");
		
		if (enl.size() != zhl.size()) {
			System.err.println("The size of the English list " + enl.size() + " not equal to the size of Chinese list "+zhl.size());
		}
		
		int len = zhl.size();
		if (len > enl.size()) len = enl.size();
		HashMap<String, String> hmap = new HashMap<String, String>();
		for (int i = 0; i<len; i++) {
			hmap.put(enl.get(i), zhl.get(i));
		}
		return hmap;
	}
	
	static ArrayList<String> readRegionList(String filename, String charset) throws FileNotFoundException, IOException {
		FileInputStream fis = new java.io.FileInputStream(filename);
		LineNumberReader lr;
		if (charset != null) lr = new LineNumberReader(new java.io.InputStreamReader(fis, charset));
		else lr = new LineNumberReader(new java.io.InputStreamReader(fis));
		ArrayList<String>ret = new ArrayList<String>();
		while (true) {
			String str = lr.readLine();
			if (str == null) break;
			
			str = str.trim();
		    if (str.length() == 0) continue;
		    ret.add(str);
		}
		lr.close();
		fis.close();
		return ret;
	}

	public static ArrayList<UnivEntry> readUniversityList() throws IOException {
	    String f = globalFileName;
	    String cnf = cnFileName;
	    List<String> enl = UniversityData.readRegionList(f, "UTF-8");
	    List<String> zhl = UniversityData.readRegionList(cnf, "UTF-16");
	   
	    ArrayList<UnivEntry> ret = new ArrayList<UnivEntry>();
	    int len = zhl.size();
	    if (len> enl.size()) len = enl.size();
	    for (int i = 0; i< len; i++) {
	    	String un = enl.get(i).trim();
			
			UnivEntry ue = new UnivEntry(un, zhl.get(i), 0);
			ret.add(ue);
		}
		
		return ret;
	} 

}

class UnivEntry implements Comparable<UnivEntry>{
	String schoolName = null;
	String chineseName = null;
	int score = 0;	
	public UnivEntry(String art, String chineseName, int score) {
		this.schoolName= art;
		this.chineseName = chineseName;
		this.score = score;
	}
	public int compareTo(UnivEntry b) {
		return  (b.score -score) ;
		
	}	
}

/***
 * inlinkScore,maxScore 专业分数
 * averageEndowment maxAverageEndowment 平均资金
 * facultyStudentRatio maxFacultyStudentRatio师生比例
 */
class OutUnivEntry extends UnivEntry{

    long inlinkScore = 0;
    long almaMater = 0;
    long almaMaterRadio = 0;
    long averageEndowment = 0;
    long endowment = 0;
    long facultyStudentRatio = 0;
    long averageinlinkScor = 0;
    long maslink = 0;
    long maclast10yearslink = 0;
    long twitternum = 0;
    long twitterStudentRatio = 0;
    long masReferenceCount = 0;
    long masReferenceCount10YeatsCount = 0;
    String chineseName = null;
    
    long FinancialSupport =0;    //资金支持
    long EducationQualit = 0;    //师资力量
    long Productivity = 0;    //校友质量
    long AcademicCapability = 0; //学术能力
    long Reputation = 0;    //声誉
    long SocialMediaActivity = 0;   //社会影响力
    
    public OutUnivEntry(String art, String chineseName, int score) {
        super(art, chineseName, score);
    }
   public void calculate(){
//       System.out.println("averageinlinkScor:"+averageinlinkScor);
//       System.out.println("maclast10yearslink:"+maclast10yearslink);
//       System.out.println("maslink:"+maslink);
//       System.out.println("averageinlinkScor:"+averageinlinkScor);
//       System.out.println("almaMater:"+almaMater);
//       System.out.println("inlinkScore:"+inlinkScore);
//       System.out.println("averageEndowment:"+averageEndowment);
//       System.out.println("endowment:"+endowment);
//     System.out.println("twitternum:"+twitternum);
//     System.out.println("twitterStudentRatio:"+twitterStudentRatio);
       this.Reputation = (long) (this.inlinkScore*0.8+this.twitternum *0.1 + this.twitterStudentRatio * 0.1);
       this.Productivity = (long)(this.almaMater*0.5 + this.almaMaterRadio*0.5);
       this.EducationQualit = (long) (this.facultyStudentRatio *0.8 + this.maslink*0.2);
       this.FinancialSupport = (long) (this.averageEndowment*0.5 + this.endowment*0.5);
//       this.AcademicCapability = (long) (this.maslink *0.3 + this.maclast10yearslink * 0.3+ this.masReferenceCount * 0.4);
       this.AcademicCapability = (long) (this.masReferenceCount10YeatsCount *0.5 +  this.masReferenceCount * 0.5);
//       this.SocialMediaActivity = (long) ();
   }
    
}
